import {fromJS} from "immutable"
import { 
  GET_INDEX_CITY,
  GET_INDEX_DATA,
  SET_CURRENT_CITY,
  GET_HOTSRECOMMEND_DATA,
  GET_TOURRECOMMEND_DATA,
  GET_FLOORSHOW_DATA,
  GET_RECOMMDED_DATA

} from "@/components/main/index/actionCreator";

const defaultStore=fromJS({
   cityList:[],
   indexTopData:{},
   hotsrecommendData:[],
   tourrecommendData:[],
   floorShowData:[],
   recommendData:[],
   currentCity:  {
    city_id: 0,
    abbreviation: "",
    name: "全国"
}
})
export default (state=defaultStore,action)=>{
    switch (action.type) {

        case GET_INDEX_CITY:
         var citydata=  action.val.data.data;
            var arr=[];
            for(let key in citydata){
            arr.push(citydata[key]) 
            }
          return state.update("cityList",val=>val=arr)


        case GET_INDEX_DATA:
         var topdata= action.val.data.data;
         
          return state.update("indexTopData",val=>val=topdata)

        case SET_CURRENT_CITY:
        var res= action;
        return state.update("currentCity",val=>val=fromJS(res))
        //热门演出 

        case GET_HOTSRECOMMEND_DATA:
        var recommend= action.val.data.data.hots_show_list;
        recommend.push({title:"热门演出"})

        return state.update("hotsrecommendData",val=>val=fromJS(recommend))
        //巡回演出

        case GET_TOURRECOMMEND_DATA:
        var tourrecommend= action.val.data.data.tour_show_list.slice(0,6);
        tourrecommend.title="巡回演出";
        return state.update("tourrecommendData",val=>val=tourrecommend)

        //演唱会 音乐剧/...数据

        case GET_FLOORSHOW_DATA:
        var floorshow= action.val;
        return state.update("floorShowData",val=>val=fromJS(floorshow))

        //为你推荐数据
        case GET_RECOMMDED_DATA:
        return state.update("recommendData",(val)=>{
          return val.concat(fromJS(action.val));
        })
        default:
            return state;
    }
  
    
    
}